package datastructure_algorithm.map;

import java.util.ArrayList;

import datastructure_algorithm.set.FileOperation;

public class _Test {

	static String filename = "/home/zc/git/learn-java/src/main/resources/pride-and-prejudice.txt";

	public static void main(String[] args) {
		testLinkedListMap();
		System.out.println();
		testBSTMap();
	}

	private static void testLinkedListMap() {
		System.out.println("Pride and Prejudice");

		ArrayList<String> words1 = new ArrayList<>();
		if (FileOperation.readFile(filename, words1)) {
			System.out.println("Total words: " + words1.size());

			LinkedListMap<String, Integer> map = new LinkedListMap<>();
			for (String word : words1) {
				if (map.contains(word)) {
					map.set(word, map.get(word) + 1);
				} else {
					map.add(word, 1);
				}
			}
			System.out.println("Total different words: " + map.getSize());
			System.out.println("Frequency of PRIDE: " + map.get("pride"));
			System.out.println("Frequency of PREJUDICE: " + map.get("prejudice"));
		}
	}
	
	private static void testBSTMap() {
		System.out.println("Pride and Prejudice");

		ArrayList<String> words1 = new ArrayList<>();
		if (FileOperation.readFile(filename, words1)) {
			System.out.println("Total words: " + words1.size());

			Map<String, Integer> map = new BSTMap<>();
			for (String word : words1) {
				if (map.contains(word)) {
					map.set(word, map.get(word) + 1);
				} else {
					map.add(word, 1);
				}
			}
			System.out.println("Total different words: " + map.getSize());
			System.out.println("Frequency of PRIDE: " + map.get("pride"));
			System.out.println("Frequency of PREJUDICE: " + map.get("prejudice"));
		}
	}
}
